package com.sx.zongzhi.presenter;

import android.content.Context;

import com.sx.zongzhi.bean.MailBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.modle.HeadParamBean;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BasePageListBean;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.IInBoxView;

import java.util.Map;

/**收件箱
 * Created by admin on 2017/12/1.
 */
public class InBoxPest {

    private IInBoxView iInBoxView;

    public InBoxPest(IInBoxView iInBoxView) {
        this.iInBoxView=iInBoxView;
    }

    public void getInBoxList(Context context, int page, int rows, String searchTitle,
                             String searchSenderName, String searchMessageType,
                             String searchTimeStart, String searchTimeEnd){
        Map<String,Object> map = HeadParamBean.getHead(context);
        map.put("page", page);
        map.put("rows", rows);
        if (!BaseUtil.isEmpty(searchTitle)){
            map.put("searchPlatformMessageVo.title",searchTitle);
        }
        if (!BaseUtil.isEmpty(searchSenderName)){
            map.put("searchPlatformMessageVo.senderName",searchSenderName);
        }
        if (!BaseUtil.isEmpty(searchMessageType)){
            map.put("searchPlatformMessageVo.messageType",searchMessageType);
        }
        if (!BaseUtil.isEmpty(searchTimeStart)){
            map.put("searchPlatformMessageVo.sendTimeStart",searchTimeStart);
        }
        if (!BaseUtil.isEmpty(searchTimeEnd)){
            map.put("searchPlatformMessageVo.sendTimeEnd",searchTimeEnd);
        }
        new ApiManager().getInBoxList(map, new BaseCallBack<BaseResult<BasePageListBean<MailBean>>>() {
            @Override
            public void onSuccess(BaseResult<BasePageListBean<MailBean>> response) {
                iInBoxView.getInBoxListSuccess(response.getData().rows,response.getData().getTotal());
            }
            @Override
            public void onFailures(String message) {
                iInBoxView.showError(message);
            }
        });
    }
}
